// mircoApp/new-auction/new_auction_Income_detail/new_auction_Income_detail.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageName: "new_auction_Income_detail",
    active: 0,
    info: [],
    list: [],

    isLoadMore: true,
    page: 1,
    total_page: 0
    // tag=new_auction_Profit_detail
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.tag) {
      this.setData({
        pageName: options.tag,
      });
    }
    let yz_basic_info = wx.getStorageSync('yz_basic_info');
    switch (this.data.pageName) {
      case "new_auction_Profit_detail":
        wx.setNavigationBarTitle({
          title: "盈利明细",
        });
        break;
      case "new_auction_Income_detail":
        wx.setNavigationBarTitle({
          title: "收益详情",
        });
        break;
      case "new_auction_supplier":
        wx.setNavigationBarTitle({
          title: yz_basic_info.plugin_setting.new_auction.plugin_name+"供应商奖励",
        });
      default:
        break;
    }
    this.getData();
  },
  towithdraw() {
    wx.navigateTo({
      url: '/mircoApp/new-auction/new_auction_withdraw/new_auction_withdraw?tag=income',
    })
  },
  tabChange(e) {
    console.log(e);
    this.setData({
      active: e.detail.name,
      page: 1,
      total_page: 0,
      isLoadMore: false
    })
    let json = {};
    if (this.options.tag == "new_auction_Profit_detail") {
      json.source = 1;
    } else if (this.options.tag == "new_auction_Income_detail") {
      json.source = 2;
    } else {
      json.source = 3;
    }
    this.getList(json);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.isLoadMore) {
      this.getMoreData();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
  async getMoreData() {
    if (!this.data.isLoadMore) return;
    this.data.isLoadMore = false;
    if (this.data.page >= this.data.total_page) {
      return;
    } else {
      this.setData({
        page: this.data.page + 1,
        status: this.data.active
      })
      let json = {
        page: this.data.page,
        status: this.data.active
      };
      if (this.options.tag == "new_auction_Profit_detail") {
        json.source = 1;
      } else if (this.options.tag == "new_auction_Income_detail") {
        json.source = 2;
      } else {
        json.source = 3;
      }
      let {
        data
      } = await app._postNetWork({
        url: app.getNetAddresss("plugin.new-auction.frontend.reward.index"),
        data: json
      })
      if (data.result) {
        this.data.isLoadMore = false;
        this.setData({
          list: this.data.list.concat(data.data.data)
        })
      } else {
        app.tips(data.msg);
        this.data.isLoadMore = false;
      }
    }
  },
  async getData() {
    // new_auction_Profit_detail 盈利,会员自己
    // new_auction_Income_detail 上级
    // new_auction_supplier 供应商
    let urlstr = "plugin.new-auction.frontend.reward.summary";
    let json = {
      source: ""
    };
    if (this.options.tag == "new_auction_Profit_detail") {
      json.source = 1;
    } else if (this.options.tag == "new_auction_Income_detail") {
      json.source = 2;
    } else {
      json.source = 3;
    }
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss(urlstr),
      data: json
    })
    if (data.result) {
      this.setData({
        info: data.data
      })
      this.getList(json);
    } else {
      app.tips(data.msg)
    }
  },
  async getList(json) {
    json.status = this.data.active;
    json.page = this.data.page;
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.new-auction.frontend.reward.index"),
      data: json
    })
    if (data.result) {
      this.setData({
        list: data.data.data,
        isLoadMore: true,
        total_page: data.data.last_page,
      })
    } else {
      app.tips(data.msg)
    }
  }
});